<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改课程管理')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css"/>
    <style type="text/css">
        .modal-backdrop {
            background-color: rgba(0, 0, 0, 0) !important;
            z-index: -1 !important;
        }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-course-edit" th:object="${tianliangCourse}">
        <input name="courseId" th:field="*{courseId}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">课程名称：</label>
            <div class="col-sm-8">
                <input class="form-control" name="courseName" required th:field="*{courseName}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">课程副标题：</label>
            <div class="col-sm-8">
                <input class="form-control" name="courseOtherName" th:field="*{courseOtherName}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">课程简介：</label>
            <div class="col-sm-8">
                <input class="form-control" th:field="*{courseText}" type="hidden">
                <div class="summernote" id="courseText"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">课程难度(0是简单,1是一般,2是困难,3是地狱,4是深渊)：</label>
            <div class="col-sm-8">
                <select class="form-control m-b" name="courseDifficulty"
                        required th:with="type=${@dict.getType('course_difficulty')}">
                    <option th:each="dict : ${type}" th:field="*{courseDifficulty}" th:text="${dict.dictLabel}"
                            th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">是否打折(0是原价,1是打折)：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('course_discount')}">
                    <input name="courseDiscount" required th:field="*{courseDiscount}"
                           th:id="${'courseDiscount_' + dict.dictCode}" th:value="${dict.dictValue}" type="radio">
                    <label th:for="${'courseDiscount_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商品价格：</label>
            <div class="col-sm-8">
                <input class="form-control" name="coursePrice" required th:field="*{coursePrice}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">打折价格：</label>
            <div class="col-sm-8">
                <input class="form-control" name="courseNewPrice" th:field="*{courseNewPrice}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">打折描述：</label>
            <div class="col-sm-8">
                <input class="form-control" name="courseNewPriceText" th:field="*{courseNewPriceText}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">排序：</label>
            <div class="col-sm-8">
                <input class="form-control" name="courseSort" required th:field="*{courseSort}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">是否轮播(0是是,1是否)：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('course_carousel')}">
                    <input name="courseCarousel" required th:field="*{courseCarousel}"
                           th:id="${'courseCarousel_' + dict.dictCode}" th:value="${dict.dictValue}" type="radio">
                    <label th:for="${'courseCarousel_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">是否精品推荐(0是是,1是否)：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('course_carousel')}">
                    <input name="courseBoutique" required th:field="*{courseBoutique}"
                           th:id="${'courseBoutique_' + dict.dictCode}" th:value="${dict.dictValue}" type="radio">
                    <label th:for="${'courseBoutique_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">是否免费(0是是,1是否)：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('course_carousel')}">
                    <input name="courseFree" required th:field="*{courseFree}"
                           th:id="${'courseFree_' + dict.dictCode}" th:value="${dict.dictValue}" type="radio">
                    <label th:for="${'courseFree_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">是否对外(0是是,1是否)：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('course_carousel')}">
                    <input name="courseForeign" required th:field="*{courseForeign}"
                           th:id="${'courseForeign_' + dict.dictCode}" th:value="${dict.dictValue}" type="radio">
                    <label th:for="${'courseForeign_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">封面上传：</label>
            <div class="col-sm-8">
                <input name="courseCover" th:field="*{courseCover}" type="hidden">
                <div class="file-loading">
                    <input class="form-control file-upload" id="courseCover" name="file" type="file">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">轮播图：</label>
            <div class="col-sm-8">
                <input name="courseSlideshow" th:field="*{courseSlideshow}" type="hidden">
                <div class="file-loading">
                    <input class="form-control file-upload" id="courseSlideshow" name="file" type="file">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">是否展示详情(0是是,1是否)：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('course_carousel')}">
                    <input name="courseDetails" required th:field="*{courseDetails}"
                           th:id="${'courseDetails_' + dict.dictCode}" th:value="${dict.dictValue}" type="radio">
                    <label th:for="${'courseDetails_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">详情介绍,文件上传：</label>
            <div class="col-sm-8">
                <input name="courseDetailsChick" th:field="*{courseDetailsChick}" type="hidden">
                <div class="file-loading">
                    <input class="form-control file-upload" id="courseDetailsChick" name="file" type="file">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">播放量：</label>
            <div class="col-sm-8">
                <input class="form-control" name="courseShow" th:field="*{courseShow}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">是否上线(0是上线,1是下线)：</label>
            <div class="col-sm-8">
                <select class="form-control m-b" name="courseState" required
                        th:with="type=${@dict.getType('course_carousel')}">
                    <option th:each="dict : ${type}" th:field="*{courseState}" th:text="${dict.dictLabel}"
                            th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input class="form-control" name="courseOtherText" th:field="*{courseOtherText}" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: summernote-js"/>
<script th:inline="javascript">
    var prefix = ctx + "tianliangedu/course";
    $("#form-course-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-course-edit').serialize());
        }
    }

    $(".file-upload").each(function (i) {
        var val = $("input[name='" + this.id + "']").val()
        $(this).fileinput({
            'uploadUrl': ctx + 'common/upload',
            initialPreviewAsData: true,
            initialPreview: [val],
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
        $(this).fileinput('_initFileActions');
    });

    $(function () {
        $('.summernote').each(function (i) {
            $('#' + this.id).summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function (contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function (files) {
                        var obj = this;
                        var data = new FormData();
                        data.append("file", files[0]);
                        $.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                            data: data,
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'json',
                            success: function (result) {
                                if (result.code == web_status.SUCCESS) {
                                    $('#' + obj.id).summernote('insertImage', result.url);
                                } else {
                                    $.modal.alertError(result.msg);
                                }
                            },
                            error: function (error) {
                                $.modal.alertWarning("图片上传失败。");
                            }
                        });
                    }
                }
            });
            var content = $("input[name='" + this.id + "']").val();
            $('#' + this.id).summernote('code', content);
        })
    });
</script>
</body>
</html>